home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.MDIForm MDIForm1
- Appearance = 0 'Flat
- BackColor = &H8000000C&
- Caption = "Socket Server"
- ClientHeight = 6405
- ClientLeft = 3135
- ClientTop = 3360
- ClientWidth = 8340
- Height = 7095
- Left = 3075
- LinkTopic = "MDIForm1"
- Top = 2730
- Width = 8460
- Begin VB.PictureBox Picture1
- Align = 1 'Align Top
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- BorderStyle = 0 'None
- BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 1515
- Left = 0
- ScaleHeight = 1515
- ScaleWidth = 8340
- TabIndex = 0
- Top = 0
- Width = 8340
- Begin VB.Timer Timer1
- Enabled = 0 'False
- Interval = 1000
- Left = 7650
- Top = 780
- End
- Begin VB.TextBox textLocalAddress
- Appearance = 0 'Flat
- Height = 285
- Left = 1335
- TabIndex = 3
- Text = "0.0.0.0"
- Top = 135
- Width = 1425
- End
- Begin VB.TextBox textLocalPort
- Appearance = 0 'Flat
- Height = 285
- Left = 3870
- TabIndex = 2
- Text = "1024"
- Top = 135
- Width = 555
- End
- Begin VB.ListBox listStatus
- Appearance = 0 'Flat
- Height = 810
- Left = 1335
- TabIndex = 1
- Top = 465
- Width = 6120
- End
- Begin AsocketLib.AsyncSocket AsyncSocket1
- Left = 7560
- Top = 240
- _Version = 327680
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 0
- ReceiveBufferSize= 8192
- SendBufferSize = 8192
- BroadcastEnabled= 0 'False
- LingerEnabled = 0 'False
- RouteEnabled = -1 'True
- KeepAliveEnabled= 0 'False
- OutOfBandEnabled= 0 'False
- ReuseAddressEnabled= 0 'False
- TCPNoDelayEnabled= 0 'False
- LingerMode = 0
- LingerTime = 0
- EventMask = 63
- LocalPort = 0
- RemotePort = 0
- SocketType = 0
- LocalAddress = ""
- RemoteName = ""
- RemoteAddress = ""
- ReceiveTimeout = -1
- SendTimeout = -1
- End
- Begin VB.Line Line2
- BorderColor = &H00FFFFFF&
- X1 = 0
- X2 = 8415
- Y1 = 90
- Y2 = 90
- End
- Begin VB.Line Line1
- BorderColor = &H00404040&
- BorderWidth = 2
- X1 = 15
- X2 = 7785
- Y1 = 1380
- Y2 = 1380
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Local Address:"
- ForeColor = &H80000008&
- Height = 225
- Index = 0
- Left = 165
- TabIndex = 6
- Top = 150
- Width = 1155
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Local Port:"
- ForeColor = &H80000008&
- Height = 210
- Index = 1
- Left = 2940
- TabIndex = 5
- Top = 150
- Width = 840
- End
- Begin VB.Label Label2
- Alignment = 1 'Right Justify
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Status:"
- ForeColor = &H80000008&
- Height = 285
- Left = 435
- TabIndex = 4
- Top = 435
- Width = 855
- End
- End
- Begin VB.Menu FileMenu
- Caption = "&File"
- Begin VB.Menu FileExit
- Caption = "E&xit"
- End
- End
- Begin VB.Menu WindowMenu
- Caption = "&Window"
- WindowList = -1 'True
- End
- Begin VB.Menu HelpMenu
- Caption = "&Help"
- Begin VB.Menu HelpAbout
- Caption = "&About"
- End
- End
- Attribute VB_Name = "MDIForm1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub AsyncSocket1_OnAccept(ByVal SocketHandle As Long, ByVal ErrorCode As Integer)
- Dim foo As New formSession
- foo.textSocketHandle = CStr(SocketHandle)
- listStatus.AddItem "OnAccept" & Str(ErrorCode)
- listStatus.AddItem "Socket Address: " & foo.AsyncSocket1.SocketAddress
- If Trim$(foo.AsyncSocket1.RemoteAddress) <> "" Then
- foo.lblClientIP = foo.AsyncSocket1.RemoteAddress
- Else
- foo.lblClientIP = "Unknown IP"
- End If
- foo.lblClientPort = CStr(foo.AsyncSocket1.RemotePort)
- End Sub
- Private Sub AsyncSocket1_OnClose(ByVal ErrorCode As Integer)
- listStatus.AddItem "Close" & Str(ErrorCode)
- AsyncSocket1.Action = ASocketClose
- AsyncSocket1.Action = ASocketCreate
- AsyncSocket1.Action = ASocketListen
- End Sub
- Private Sub AsyncSocket1_OnConnect(ByVal ErrorCode As Integer)
- listStatus.AddItem "Connect" & Str(ErrorCode)
- '
- ' Remove all of the following lines if you have a known
- ' address.
- '
- AsyncSocket1.LocalPort = 1024
- AsyncSocket1.LocalAddress = AsyncSocket1.SocketAddress
- textLocalAddress = AsyncSocket1.LocalAddress
- AsyncSocket1.Action = ASocketClose
- AsyncSocket1.Action = ASocketCreate
- AsyncSocket1.Action = ASocketListen
- End Sub
- Private Sub MDIForm_Load()
- '
- ' note: When running as a client on a service which
- ' provides you with an ip address when you connect the
- ' program must go through some hoops to get the assigned
- ' ip address to use with this server example.
- '
- ' This sample program was tested on such a server and
- ' handles the problem. For a _real_ server this is
- ' somewhat unrealistic since a real server would
- ' be expected to have a known address and presumably
- ' you would know what that address is.
- '
- AsyncSocket1.LocalPort = 0
- AsyncSocket1.LocalAddress = "0.0.0.0"
- '
- ' Winsock won't tell us what our ip address is until
- ' after we connect to some remote socket. Here I've
- ' chosen to use mit.edu.
- '
- AsyncSocket1.RemotePort = 13
- '
- ' If you can't do name lookups comment out the following
- ' three lines and uncomment the one following them.
- '
- ' Also, if you have a known server address then remove
- ' the following three lines, uncomment the fourth, and
- ' supply the appropriate address there. Be sure to remove
- ' the indicated lines in OnConnect as well in this case.
- '
- AsyncSocket1.RemoteNameAddrXlate = True
- AsyncSocket1.RemoteName = "mit.edu"
- AsyncSocket1.RemoteNameAddrXlate = False
- ' AsyncSocket1.RemoteAddress = "18.72.2.1"
- AsyncSocket1.Action = ASocketCreate
- On Error Resume Next
- '
- ' Remove the following 5 lines if you have a known address
- '
- AsyncSocket1.Action = ASocketConnect
- If (Err <> 0 And Err <> 10035) Then
- MsgBox Error
- End If
- On Error GoTo 0
- '
- ' Uncomment the following two lines if you have a known
- ' address.
- '
- 'AsyncSocket1.Action = ASocketCreate
- 'AsyncSocket1.Action = ASocketListen
- End Sub
- Private Sub MDIForm_Resize()
- line1.Y1 = picture1.Height - Screen.TwipsPerPixelY
- line1.Y2 = line1.Y1
- line2.Y1 = 0
- line2.Y2 = 0
- line1.X1 = 0
- line1.X2 = picture1.Width
- line2.X1 = 0
- line2.X2 = picture1.Width
- listStatus.Width = Me.ScaleWidth - (listStatus.Left + 5 * Screen.TwipsPerPixelX)
- End Sub
-